using Minio;
using Minio.DataModel.Args;

namespace DiLu.Expansion.File.Operates.Minio.Tools;

public static class MinioFileTool
{
    /// <summary>
    ///     创建桶，如果桶存在不创建
    /// </summary>
    /// <param name="minioClient">Minio客户端</param>
    /// <param name="bucketName">桶名称</param>
    /// <param name="fileName">文件名称</param>
    public static async Task<bool> FileExistsAsync(this IMinioClient minioClient, string bucketName, string fileName)
    {
        try
        {
            var statObjectArgs = new StatObjectArgs()
                .WithBucket(bucketName)
                .WithObject(fileName);
            await minioClient.StatObjectAsync(statObjectArgs);
            return true;
        }
        catch
        {
            return false;
        }
    }
}